var vm = new Vue({
	el: '#app',
	data: {
		items: [],
		loaded: false
	},
	mounted: function() {
		dataForCashReceiptsAndGetInWalletQRCode();
		getUserAccount();
	}
});
/**
 * 复制功能 
 */
function copyLink() {
	var sUserAgent = navigator.userAgent.toLowerCase();
	var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
	var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
	if(bIsIpad || bIsIphoneOs) {
		//XXX 这里是IOS的代码
		var copyDOM = document.querySelector('#recAddr'); //要复制文字的节点    
		var range = document.createRange();
		// 选中需要复制的节点    
		range.selectNode(copyDOM);
		// 执行选中元素    
		window.getSelection().addRange(range);
		// 执行 copy 操作    
		var successful = document.execCommand('copy');
		try {
			var msg = successful ? 'successful' : 'unsuccessful';
			$.toptip("复制链接成功！", 'success');
		} catch(err) {
			$.toptip("复制链接失败！", 'error');
		}
		// 移除选中的元素    
		window.getSelection().removeAllRanges();
	} else {
		//XXX 这里是android的代码
		var Url2 = document.getElementById("recAddr").innerText;
		var oInput = document.createElement('input');
		oInput.value = Url2;
		document.body.appendChild(oInput);
		oInput.select(); // 选择对象
		document.execCommand("Copy"); // 执行浏览器复制命令
		oInput.className = 'oInput';
		oInput.style.display = 'none';
		$.toptip("复制链接成功！", 'success');
	}
}
/**
 * 渲染二维码的方法
 */
function dataForCashReceiptsAndGetInWalletQRCode() {
	var content = localStorage.getItem("content");
	var obj = JSON.parse(content);
	$("#getInWalletQRCodeImg").attr("src", ip + "platform/userWallet/getInWalletQRCode.m?coinId=" + obj.coinId + "&t=" + Math.random());
	$("#img").attr("src",obj.tradeCoin.img);
	$("#title").text(obj.tradeCoin.title);
	$("#name").text(obj.tradeCoin.name);
}

function getUserAccount() {
	var content = localStorage.getItem("content");
	var obj = JSON.parse(content);
	$.ajax({
		type: "GET",
		url: ip + "platform/userAccount/getUserAccount.m?coinId=" + obj.coinId,
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(data) {
			if(data.statusCode == 0) {
				vm.loaded = true;
				$("#recAddr").text(data.result.recAddr);
			} else if(data.statusCode == 1000) {
				loginError();
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}